/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2021-10-08 16:26:17
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-05-09 14:12:16
 * @FilePath: \code\cwp-front\pc-collaboration\config\plugins\FiberPlugin.js
 * @Description:
 */
// 用于Pc依赖注入v5的外置文件
const seeyonBuild = require('../../seeyonBuild.json');
const PR = seeyonBuild.pathResolve;

const smpOption = {
    headerJS:
        process.env.NODE_ENV == 'development'
            ? `${PR.staticPath}/main.do?method=commonHeaderJs`
            : `${PR.staticPath}/rest/cap4/form/headerJs${PR.staticSuffix}`,
    csdkJS: `/static/app/collaboration/js/csdk.js${PR.staticSuffix}`,
    js: [
        `${PR.staticPath}/common/all-min.js`,
        `${PR.staticPath}/common/ctpUi/dist/js/ctpUi.min.js`,
        `${PR.staticPath}/common/workflow/workflowDesigner_ajax.js${PR.staticSuffix}`,
        `${PR.staticPath}/common/workflow/workflowDesigner_api-min.js${PR.staticSuffix}`,
        `${PR.staticPath}/common/page-guide/index.js${PR.staticSuffix}`,
    ],
    css: [
        `${PR.staticPath}/common/all-min.css${PR.staticSuffix}`,
        `${PR.staticPath}/apps_res/collaboration/css/summary-jsp-min.css${PR.staticSuffix}`,
        `${PR.staticPath}/skin/dist/min/skinComponents-defaultTheme-min.css${PR.staticSuffix}`,
        `${PR.staticPath}/common/ctpUi/dist/css/ctpUi.css${PR.staticSuffix}`,
        `${PR.staticPath}/skin/xicon/xicon-min.css${PR.staticSuffix}`,
        `${PR.staticPath}/portal/icons/default/fonts/plane/iconfont.css${PR.staticSuffix}`,
    ],
};

function FiberPlugin(versionData) {
    // 本地启动，自动添加一些外部依赖。如：$
    if (process.env.NODE_ENV == 'development') {
    }
    this.fiberOptions = smpOption;
    this.versionData = versionData;
}

FiberPlugin.prototype.apply = function (compiler) {
    var fiberOptions = this.fiberOptions;
    var versionData = this.versionData;
    compiler.plugin('compilation', function (compilation) {
        compilation.plugin(
            'html-webpack-plugin-before-html-generation',
            function (htmlPluginData, callback) {
                htmlPluginData.plugin.options.version = versionData.version;
                htmlPluginData.plugin.options.fiberOptions = fiberOptions;
            }
        );
    });
};

module.exports = FiberPlugin;
